<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.team5.admin.Admin"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="java.util.ArrayList"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ include file="../session.jsp"%>
<%@ include file="../dbcon.jsp"%>
<%
	
	int seq = web.getInt("seq");

	if (seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}

%>
<%
	/** 관리자 계정 조회 */
	Admin admin = new Admin();
	AdminItem item = admin.viewAdmin(seq);
	
	if (item == null) {
		db.disconnect();
		web.goPage(null, "데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<%@ include file="../head.jsp"%>
</head>
<body>
	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h1>
				관리자 계정 수정 - <small>관리자 계정을 수정하세요.</small>
			</h1>
		</div>

		<form id="frmAdminEdit" class="form-horizontal" role="form"
			method="post" action="editAdminOk.jsp">

			<!-- 관리자 일련번호 자동입력 -->
			<input type="hidden" name="seq" value="<%=seq%>">

			<fieldset>

				<!-- 입력양식 -->
				<div class="form-group">
					<label for="admin_id" class="col-md-2 control-label">아이디</label>
					<div class="col-md-10">
						<input type="text" class="form-control" id="admin_id"
							name="admin_id" value=<%= item.getAdmin_id() %>
							disabled="disabled"> <input type="hidden" name="admin_id"
							value="<%= item.getAdmin_id() %>">
					</div>
				</div>

				<div class="form-group">
					<label for="admin_pw" class="col-md-2 control-label">비밀번호</label>
					<div class="col-md-10">
						<input type="password" class="form-control" id="admin_pw"
							placeholder="비밀번호를 입력하세요" name="admin_pw"
							value=<%=item.getAdmin_pw()%> autofocus>
					</div>
				</div>

				<div class="form-group">
					<label for="admin_level" class="col-md-2 control-label">레벨</label>
					<div class="col-md-10">
						<select class="form-control" id="admin_level" name="admin_level">
							<option>---- 선택하세요 ----</option>
							<option value="1" <%if (item.getAdmin_level() == 1) { %> selected
								<%}%>>1 level</option>
							<option value="2" <%if (item.getAdmin_level() == 2) { %> selected
								<%}%>>2 level</option>
							<option value="3" <%if (item.getAdmin_level() == 3) { %> selected
								<%}%>>3 level</option>
							<option value="4" <%if (item.getAdmin_level() == 4) { %> selected
								<%}%>>4 level</option>
							<option value="5" <%if (item.getAdmin_level() == 5) { %> selected
								<%}%>>5 level</option>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="admin_comment" class="col-md-2 control-label">코멘트</label>
					<div class="col-md-10">
						<input type="text" class="form-control" id="admin_comment"
							placeholder="코멘트를 입력하세요" name="admin_comment"
							value=<%=item.getAdmin_comment()%>>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>
	<% db.disconnect(); %>
	<!-- Javascript -->
	<script src="/Team-Project/assets/js/jquery.js"></script>
	<script src="/Team-Project/assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="/Team-Project/assets/js/string.js"></script>
	<!-- 구현부분 -->
	<script type="text/javascript">
		// jquery main()
		$(function() {
			$("#frmAdminEdit").submit(function() {
				
				// 아이디 입력여부 검사
				if (!$("input[name='admin_id']").val().isValue()) {
					alert("아이디를 입력하세요.");
					$("input[name='admin_id']").focus();
					return false;
				}
				
				// 아이디 형식 검사
				if (!$("input[name='admin_id']").val().isAlphabetNum()) {
					alert("아이디는 영어와 숫자로만 입력 가능합니다.");
					$("input[name='admin_id']").focus();
					return false;
				}
				
				// 비밀번호 입력여부 검사
				if (!$("input[name='admin_pw']").val().isValue()) {
					alert("비밀번호를 입력하세요.");
					$("input[name='admin_pw']").focus();
					return false;
				}
				
				// 비밀번호 형식 검사
				if (!$("input[name='admin_pw']").val().isAlphabetNum()) {
					alert("비밀번호는 영어와 숫자로만 입력 가능합니다.");
					$("input[name='admin_pw']").focus();
					return false;
				}
				
				// 레벨 선택여부 검사
				if ($("select[name='admin_level'] > option:selected").index() < 1) {
					alert("레벨을 입력하세요.");
					$("select[name='admin_level']").focus();
					return false;
				}
				
				// 코멘트 입력여부 검사
				if (!$("input[name='admin_comment']").val().isValue()) {
					alert("코멘트를 입력하세요.");
					$("input[name='admin_comment']").focus();
					return false;
				}
			});
		});
	</script>

</body>
</html>